package br.com.remedioCerto.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.com.remedioCerto.R;
import br.com.remedioCerto.model.Remedio;

public class RemedioAdapter extends BaseAdapter {
	private List<Remedio> listaRemedio;
	private Context context;
	
	public RemedioAdapter(Context context,List<Remedio> lista) {
		this.listaRemedio = lista;
		this.context = context;
	}

		
	@Override
	public int getCount() {
		return this.listaRemedio.size(); 
	}
	
	@Override
	public Remedio getItem(int position) {
		return this.listaRemedio.get(position);
	}
	
	public Integer getItemPositon(long itemId) {
		for(int pos = 0; pos<listaRemedio.size(); pos++)
			if(getItemId(pos) == itemId)return pos;
				
		return null;
	}
	
	@Override
	public long getItemId(int position) {
		return this.listaRemedio.get(position).getId();
	}
	
	public void remove(Remedio remedio){
		this.listaRemedio.remove(remedio);
		notifyDataSetChanged();
	}
	public void remove(int position){
		this.listaRemedio.remove(position);
		notifyDataSetChanged();
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.remedio_item_adapter,parent,false);
		
		ImageView imagem = (ImageView) view.findViewById(R.id.remedio_adapter_imagem);
		TextView nome =(TextView) view.findViewById(R.id.remedio_adapter_nome);
		
		imagem.setImageBitmap(this.listaRemedio.get(position).getFotoBitmap());
		nome.setText(this.listaRemedio.get(position).getNome());
		
		return view;
	}
}
